import { defineStore } from 'pinia'

// 应用状态管理模块
export const useAppStore = defineStore('app', {
  state: () => ({
    // 侧边栏状态
    sidebar: {
      opened: true,
      withoutAnimation: false
    },
    // 设备类型
    device: 'desktop',
    // 页面加载状态
    loading: false,
    // 页面标题
    title: 'Unimodel Meeting'
  }),
  
  getters: {
    // 侧边栏是否展开
    sidebarOpened: (state) => state.sidebar.opened
  },
  
  actions: {
    // 切换侧边栏
    toggleSidebar() {
      this.sidebar.opened = !this.sidebar.opened
      this.sidebar.withoutAnimation = false
    },
    
    // 关闭侧边栏
    closeSidebar(withoutAnimation) {
      this.sidebar.opened = false
      this.sidebar.withoutAnimation = withoutAnimation
    },
    
    // 打开侧边栏
    openSidebar(withoutAnimation) {
      this.sidebar.opened = true
      this.sidebar.withoutAnimation = withoutAnimation
    },
    
    // 设置设备类型
    setDevice(device) {
      this.device = device
    },
    
    // 设置加载状态
    setLoading(loading) {
      this.loading = loading
    },
    
    // 设置页面标题
    setTitle(title) {
      this.title = title
    }
  },
  
  // 持久化配置
  persist: {
    key: 'app-store',
    storage: localStorage,
    paths: ['sidebar']
  }
})